title = "分类详情页" 
url = '/:slug|[a-z0-9\-]+-c-\d+.html$' 
title = '分类详情页模板' 
layout = 'default' 
== 
use Jason\Ccshop\Controllers\Filters;
use Jason\Ccshop\Controllers\Categories; 
use Jason\Ccshop\Models\Category; 
use Jason\Ccshop\Models\Product; 
function onStart(){
	$slugArr = explode('-', str_replace('.html','', $this->param('slug'))); 
	$slug = str_replace(array('price_asc-','price_desc-','popular_desc-', 'newness_desc-'), array(), $this->param('slug')); 
	$id = array_pop($slugArr); 
	array_pop($slugArr); 
	$condition= ['id' => $id];
	$this['paramKey'] = join('-', $slugArr); 
	$categoryModel = Category::where('id', $id)->first();
	if(isset( $categoryModel['nest_depth']) && $categoryModel['nest_depth']==2){
		$parentCategory = Category::where('id', $categoryModel['parent_id'])->first();
		$this['parentCategory'] = $parentCategory;
	}

	$this['currentUrl']= str_replace(array('price_asc-','price_desc-', 'popular_desc-', 'newness_desc-'), array(), substr(request()->getRequestUri(),1));
	$this['sortFlag'] = $slugArr[0]; 
	if(!$categoryModel) { 
		return redirct('/404'); 
	} 
	$this['category'] = $categoryModel; 
	$pids= get('id_sort')?get('id_sort'):null; 
	$pageNumber = get('page')?get('page'):1; 
	if(!empty($pids)){ 
		Cookie::queue('idssort',$pids);
		Cookie::queue('cid',$id); 
		Cookie::queue('pagenumber',$pageNumber); 
	}else{ 
		$pageNumber = Cookie::get('pagenumber'); 
		$cid =Cookie::get('cid'); 
		$currentPage = get('page')?get('page'):1; 
		if($currentPage==$pageNumber && $id==$cid){
		 	$pids = Cookie::get('idssort');
		} 
	} 
	if (!empty($pids)) { 
		$pida = explode(',',$pids); 
		$pd = Product::InStock()->whereIn('id',$pida)->get(); 
		$this['adproducts']= $pd; 
		$this['pida'] = $pida; 
	} 
	if ($this['paramKey'] != $categoryModel['slug']) { 
		$paramKey = explode('-',$this['paramKey']);
		$orderArr = Filters::parseFilterKeyParams($paramKey[0]); 
		if (count($orderArr) == 2) { 
			$order = [$orderArr[0] => $orderArr[1]];
		} 
	} 
	$this['order'] = isset($order) ? $order : ['sort' => 'desc']; 
    $this['orderName'] = isset($order) ? array_keys($order)[0] : 'sort';
    $this['pageNumber'] = $pageNumber;
    $this['orderType'] = isset($order) ? reset($order) : 'desc';
	$this['products'] = App::make('Jason\Ccshop\Controllers\Products')->getCategoryProducts($categoryModel->id,$this['order']); 
} 
== 

{% set products = catalog.getCategoryProducts(category, order) %}
{% set totalPages = ceil(products.total/products.per_page) %}
{% put page_title %}{{ category.page_title }}{% endput %} 
{% set per = get('per', 20) %} 
{% put pageurl%}{{ catalog.canonicalValue(category.url, 'category')|raw }}{% endput %} 
{% put pageUrl %}
	<link rel="canonical" href="{{ ''|page }}"> 
{% if products.nextPageUrl %}
	<link rel="next" href="{{ products.nextPageUrl }}"> 
{% endif %} {% endput %} 
{% put meta_keywords %}{{ category.meta_keywords }}{% endput %} 
{% put meta_description %}{{ category.meta_description}}{% endput %} 

<div class="category_content">
	<!--<div style="overflow: hidden;margin: 5px 0 10px;">-->
	<!--<p class="allItemNum"> 全{{ products.total }} 商品 </p>-->
	<!--{{ products.render|raw }}-->
	<!--</div>-->
	<div class="swiper-container swiperMune"  id="cateListUlMune">
		<ul class="nav_four swiper-wrapper">
			{% if category.children %}
			    {% set enabled_categories = 0 %}
				{% for cate in category.children %}
				{% if cate.is_enabled %}
				{% set enabled_categories = enabled_categories + 1 %}
				{% endif %}
				{% endfor %}
			    {% if category.nest_depth==1 %}
				<li class="swiper-slide active"><a href="{{ category.url }}?rel=home">ALL</a></li>
				{% else %}
			    <li class="swiper-slide"><a href="{{ parentCategory.url }}?rel=home">ALL</a></li>
				{% endif %}
			  	{% if enabled_categories >0 %}
                {% for cate in category.children %}
				{% if cate.is_enabled %}
				{% set enabled_categories = enabled_categories + 1 %}
					<li class="swiper-slide"><a href="{{ cate.url }}?rel=home">{{ cate.name }}</a></li>
				{% endif %}
                {% endfor %}
				{% else %}
				{% if category.nest_depth==2 %}
				{% for cate in parentCategory.children %}
				{% if cate.is_enabled %}
				<li class="swiper-slide {% if cate.id==category.id %}active{% endif %}"  ><a href="{{ cate.url }}?rel=home">{{ cate.name }}</a></li>
				{% endif %}
				{% endfor %}
				{% endif %}
				{% endif %}
            {% endif %}
		</ul>

	    <div class="swiper-button-prev swiper-button-white"></div>
	    <div class="swiper-button-next swiper-button-white"></div>
	</div>
	{% partial 'catalog/list-toolbar' products = products.data %}
	<div class="itemList">
		<ul class="listUl"  id="moreProduct">
		<!-- adproducts -->
			{% if count(adproducts) > 0 %}
				{% for adproduct in adproducts %}
				<li class="product_h">
					<a href="{{ adproduct.url }}">
						<div class="productImg">
							{% for img in adproduct.feature_image %} 
							{% if loop.index == 1%}
							<img src="{{ img.path }}" data-original="{{ img.path }}" alt="{{adproduct.name}}" class="productImgH lazy"> 
							{% endif %} 
							{% endfor %}

							{% if adproduct.saled > 500 %}
							<span class="hotSale sale_">
								<img src="{{ 'assets/img/hotSale.png'|theme }}" alt="">
							</span>
							{% endif %} {% if adproduct.labels == "newest" %}
							<span class="newSale sale_">
								<img src="{{ 'assets/img/newSale.png'|theme }}" alt="">
							</span>
							{% endif %}
						</div>
						<div class="contBlock">
							<p class="txtGray1 Ellipsis">{{adproduct.name}}</p>
							<p class="txtGray">
								<b>{{ adproduct.price|formatPrice }}</b>税込 &nbsp; {% if adproduct.discount %}
								<span class="proSale">
									<b>{{ adproduct.discount }}</b>OFF</span>
								{% endif %}
							</p>
						</div>
					</a>
				</li>
				{% endfor %}
			{% endif %}
			<!-- adproducts end -->
	        {% partial "catalog/ajaxloadmoreproducts" products=products %}
		
		</ul>
            <p style="font-size:14px;text-align:center;padding:5px 0;color:#333;margin-bottom:15px;{% if totalPages > 1 %}display:none{% endif %}" class="notNewData">終わり</p>
            <button class="{{ orderName }}_{{ orderType }}" id="ajaxLoadFormoreproductsbutton" {% if totalPages <= 1 %}style="display:none"{% endif %}
                data-total-pages= "{{totalPages}}"
                data-order="{{ orderName }}_{{ orderType }}"
                data-page="2" data-category-id="{{ category.id }}" style="">もっと見る
            </button>
	</div>
</div>
{% put scripts %}
<script>
 	var indexMuneTop =  $("#cateListUlMune").offset().top; // indexMuneTop
    window.onscroll = function () {
        /**/
        var top = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        if (top > indexMuneTop) {
            $("#cateListUlMune").addClass("fixedMune").css("top",$(".logoBox").outerHeight())
        } else if (top < indexMuneTop) {
            $("#cateListUlMune").removeClass("fixedMune").removeAttr("style");

        }
        if (top > 300) {
            $(".goTop").show(200);
        } else {
            $(".goTop").hide(200);
        }

    }; 
    $(function(){
	    /******************new***/
	    var mySwiper5 = new Swiper('#cateListUlMune ', {
	        freeMode: true,
	        freeModeMomentumRatio: 0.5,
	        slidesPerView: 'auto',
	        prevButton:'.swiper-button-prev',
			nextButton:'.swiper-button-next',
	    });
	    swiperWidth = mySwiper5.container[0].clientWidth
	    maxTranslate = mySwiper5.maxTranslate();
	    maxWidth = -maxTranslate + swiperWidth / 2
        var slide = $("#cateListUlMune .swiper-wrapper").find(".swiper-slide.active")[0],
        slideLeft = slide.offsetLeft,
        slideWidth = slide.clientWidth,
        slideCenter = slideLeft + slideWidth / 2,
        swiperWidth = $("#cateListUlMune .swiper-wrapper").width();

        if (slideCenter < swiperWidth / 2) {
            mySwiper5.setWrapperTranslate(0)
        } else if (slideCenter > maxWidth) {
            mySwiper5.setWrapperTranslate(maxTranslate)
        } else {
            nowTlanslate = slideCenter - swiperWidth / 2
            mySwiper5.setWrapperTranslate(-nowTlanslate)
        }
    })

    function productH(){ 
    	$("img.lazy").lazyload({
	        effect : "fadeIn"
	    });
        var a = $(".productImg img.productImgH").eq(0).height();
        $(".productImg img.productImgH").height(a)
	   
    }
    /*click button load more products*/
    var loadingData = false;
    $("#ajaxLoadFormoreproductsbutton").click(function(){
        $("#loading").show();
         var datajson = {};
         var buttonMore = $("#ajaxLoadFormoreproductsbutton");
        datajson['order'] = buttonMore.attr("data-order");
        datajson['page'] = buttonMore.attr("data-page");
        datajson['categoryId'] = buttonMore.attr("data-category-id");
        $.request('onLoadMoreCategoryProducts', {
          data: datajson,
          update: {
            'catalog/ajaxloadmoreproducts': "@#moreProduct"
          },
          complete: function(data) { /* do something */ 

              var response=JSON.parse(data.responseText)["catalog/ajaxloadmoreproducts"];

              productH()
              $("#loading").hide();
              if(response==''){
              }else{
                //do sth
              }
          }
        })
        var thispage = buttonMore.attr('data-page');
        var nextpage = thispage ? (parseInt(thispage) + 1) : 2;
        if(nextpage>=2 && nextpage <= buttonMore.attr('data-total-pages')) {
            buttonMore.attr('data-page', nextpage);
            buttonMore.show();
            $(".notNewData").hide();
        }else{
            $(".notNewData").show();
            buttonMore.hide();
        }
       // $("#ajaxLoadFormoreproducts_page").val(nextpage);
        loadingData = true;
        setTimeout(function() {
            loadingData = false;
        }, 1000);

    });
</script>
{% endput %}

{% for key, product in products.data %} 
{% put google_tag_params %} 
var google_tag_params = { ecomm_prodid: "{{product.id}}",
ecomm_pagetype: "category", 
ecomm_totalvalue: {{product.price|ratePrice}} }; 
{% endput %} 
{% endfor %}